package net.sppan.blog.bean;

import java.util.concurrent.ConcurrentHashMap;

public enum URLParam {

	tid("p1"), userId("p2"), userName("p3"), parentId("p4"), parentName("p5"), hardwareID("p6"), offerId("p7"), price("p8");

	private String code;

	private URLParam() {
	}

	private URLParam(String code) {
		this.code = code;
	}

	private static ConcurrentHashMap<String, URLParam> map = new ConcurrentHashMap<>();
	private static ConcurrentHashMap<String, URLParam> nameMap = new ConcurrentHashMap<>();

	static {
		URLParam[] values = URLParam.values();
		for (URLParam param : values) {
			map.put(param.getCode(), param);
			nameMap.put(param.name(), param);

		}
	}

	public static URLParam getEnum(String code) {
		return map.get(code);
	}

	public static URLParam getFromName(String name) {
		return nameMap.get(name);
	}

	public String getCode() {
		return code;
	}

	public boolean equals(String code) {
		if (this.name().equals(code)) {
			return true;
		}
		return false;
	}

	public static ConcurrentHashMap<String, URLParam> getNameMap() {
		return nameMap;
	}

	public static ConcurrentHashMap<String, URLParam> getMap() {
		return map;
	}
}
